 //
//  WBNavigationController.swift
//  传智微博
//
//  Created by FYXJ（6） on 2018/8/27.
//  Copyright © 2018年 FYXJ（6）. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        edgesForExtendedLayout = UIRectEdge.top

        setNavigationBarHidden(true, animated: false)
//        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count>0 {
            viewController.hidesBottomBarWhenPushed = true
            //判断类型 if let 的as 都用？
            if let vc = viewController as? WBBaseViewController {
                
                var title = "返回"
                if childViewControllers.count == 1{
                    title = childViewControllers.first?.title ?? "返回"
                }
                //取出自定义的navItem
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent),isBack:true)
            }
        } 
        super .pushViewController(viewController, animated: animated)
    }
    
    @objc private func popToParent() {
     popViewController(animated: true)
    }
}
